package www.Zheng;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 * @Title: Demo2
 * @Author 郑雨杭
 * @Package www.Zheng
 * @Date 2024/7/7 20:23
 * @description: Reader(字符输入流)
 */
public class Demo2 {
    public static void main(String[] args) throws IOException {
        //Reader reader = new FileReader("D:\\gitee仓库\\java\\File\\test.txt");

        //一次read一个字符
        /*int rem;
        while(true){
            rem=reader.read();
            if(rem==-1){
                break;
            }else{
                System.out.print((char)rem);
            }
        }*/

        //一次read多个字符
       /* try {
            char[] rem = new char[3];
            while (true) {
                int i = reader.read(rem);
                if (i == -1) {
                    break;
                } else {
                    for (int j = 0; j < i; j++) {
                        System.out.print(rem[j]);
                    }
                }
            }
        }finally {
            reader.close();
        }*/
        try(Reader reader = new FileReader("D:\\gitee仓库\\java\\File\\test.txt")){
            char[] rem = new char[3];
            while (true) {
                int i = reader.read(rem);
                if (i == -1) {
                    break;
                } else {
                    for (int j = 0; j < i; j++) {
                        System.out.print(rem[j]);
                    }
                }
            }
        }
    }
}
